package com.guw.AWT;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestActionEvent {
    public static void main(String[] args) {
        //按下按钮,触发一些事件
        Frame f = new Frame();
        Button b1 = new Button();

        //因为addActionListener需要一个ActionListener,所以需要构造一个ActionLister
        b1.addActionListener(new MyActionListener());

        f.add(b1,BorderLayout.CENTER);
        f.pack();
        f.setVisible(true);

        windowClose(f);
    }

    //关闭窗体的事件监听方法
    private static void windowClose(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        }
    }

class MyActionListener implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        //点击按钮输出
        System.out.println("aaa");
    }
}
